from PyQt4.QtGui import QWidget
from PyQt4 import QtCore,QtGui
import pyqtgraph as pg
from .KChartViewBoxMenu import KChartViewBoxMenu
class KChartViewBox(pg.ViewBox):
	PeriodChanged=QtCore.pyqtSignal(str)
	## ViewBox used by KChart, is a QGraphicsItem holding other QGraphicsItems
	def __init__(self, *args, **kwds):
		pg.ViewBox.__init__(self, *args, **kwds)	
		self.setMouseMode(self.RectMode)
		self.menu = KChartViewBoxMenu(self) #override with our menu
	def ExceuteMenuAction(self, sAction):
	## execute the command from Context Menu
		(command,para)=sAction.split("_",2)
		if command=="Time":
			self.ChangePeriod(para)
	## change the data period displayed in the View Box
	def ChangePeriod(self,period):
		self.PeriodChanged.emit(period)
	def mouseDragEvent(self, ev):
		pass #override default drag behavior

		

